package cs131.pa1.filter.sequential;

import cs131.pa1.filter.Message;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class UniqCommand extends SequentialFilter{

	public final static String COMMAND = "uniq";

	private String para;

	private Set<String> strSet;

	public UniqCommand(List<String> commands) {

		if(commands.size() > 1){
			System.out.print(Message.INVALID_PARAMETER.with_parameter(COMMAND));
			return;
		}
		if(commands.size() == 1){
			para = null;
		} else {
			para = commands.get(1);
		}

		strSet = new HashSet<String>();
	}

	public void process(){
		if (isInterruption()){
			return;
		}
		if(input == null && para == null){
			System.out.println(Message.REQUIRES_PARAMETER.with_parameter(COMMAND));
			return;
		}

		super.process();

		if(next == null){
			for(String outInfo : output){
				System.out.println(outInfo);
			}
		}
	}

	public String processLine(String Line){

		if(strSet.contains(Line)){
			return null;
		} else {
			strSet.add(Line);
			return Line;
		}
	}	
}
